package buzz.hubu.springcloudprovider8002.Controller;


import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/info")
public class InfoCon {
    @Resource
    private DiscoveryClient client;

    @GetMapping("/all")
    public Object getAll(){
        List<String> services = client.getServices();
        String result="";
        for (String service : services) {
            List<ServiceInstance> instances = client.getInstances(service);
            for (ServiceInstance instance : instances) {
                result += instance.getInstanceId()+instance.getHost()+instance.getPort()+instance.getUri()+instance.getServiceId()+"\n";
            }
        }

        return result;

    }
}
